<?php

require_once('data/SugarBean.php');
//require_once('modules/edanz_Editor/edanz_Editor.php');
//require_once('include/utils.php');
require_once('custom/modules/Tasks/TaskCreateTasks.php');

class EditorCreateTasks {
	function EditorCreateTasks(&$bean, $event, $arguments)
	{
		global $sugar_config;
               
		$bean->fish_test = $_POST['fish_test'];

		// only run if this is a create and Employee type is prospective editor
		if (in_array($bean->employee_status, array('Prospective','ProspectiveOnHold')) && $bean->date_entered != '')
		{
			$type = 'CreateWikiAccountAndSendFishTest';
			$related_editor_id = $bean->id;
			$taskCreateTasks = new TaskCreateTasks();
                   if($bean->employee_status == 'ProspectiveOnHold')
			$taskCreateTasks->createNewRecruitmentTask($type, $related_editor_id, NULL, $_POST['first_name'].' '.$_POST['last_name'],NULL,'Pending Input');
                   else
			$taskCreateTasks->createNewRecruitmentTask($type, $related_editor_id, NULL, $_POST['first_name'].' '.$_POST['last_name']);
		}
		if($bean->fetched_row['first_name'] != $bean->first_name || $bean->fetched_row['last_name'] != $bean->last_name){
			$query = "SELECT users.* FROM users WHERE first_name = '$bean->first_name' AND last_name = '$bean->last_name' AND id != '$bean->id' AND deleted = '0'";
			$result = $bean->db->query($query, false, "Looking For Duplicate user:" . $query);
			if($bean->db->getRowCount($result) > 0){
				//$GLOBALS['log']->fatal("CONNECT | Dups found");
				$type = 'DuplicateEntryFound';
				$related_editor_id = $bean->id;
				$taskCreateTasks = new TaskCreateTasks();
				$taskCreateTasks->createNewRecruitmentTask($type, $related_editor_id, 1, $_POST['first_name'].' '.$_POST['last_name']);
			}
		}
	}
}

?>
